package main

import "fmt"

func main() {

	nums2 := [][]int{
		{1, 2, 8, 9},
		{2, 4, 9, 12},
		{4, 7, 10, 13},
		{6, 8, 11, 15},
	}

	println(find(nums2, 4, 4, 15))

}

func find(arr [][]int, rows, cols int, target int) bool {

	found := false

	if arr != nil && rows > 0 && cols > 0 {
		row, col := 0, cols-1
		for row < rows && col >= 0 {
			rightUpNum := arr[row][col]
			fmt.Println(rightUpNum)
			if rightUpNum == target {
				found = true
				break
			} else if rightUpNum > target {
				col -= 1
			} else {
				row += 1
			}
		}
	}

	return found
}
